﻿using BLL;
using DAL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;

namespace HotelCode.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RoomTypeController : ControllerBase
    {
        public RoomTypeBLL RoomTypeBLL { get; }

        public RoomTypeController(RoomTypeBLL roomTypeBLL)
        {
            RoomTypeBLL = roomTypeBLL;
        }
        [HttpPost]
        /// <summary>
        /// 添加房型
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public IActionResult RoomTypeAdd(RoomTypeModel info)
        {
            try
            {
               int res= RoomTypeBLL.RoomTypeAdd(info);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpGet]
        /// <summary>
        /// 显示查询分页
        /// </summary>
        /// <param name="totalCount"></param>
        /// <param name="totalPage"></param>
        /// <param name="Pageindex"></param>
        /// <param name="Pagesize"></param>
        /// <param name="RoomTypName"></param>
        /// <returns></returns>
        public IActionResult GetRoomTypeList( int Pageindex = 1, int Pagesize = 2, string? RoomTypName = "")
        {
            try
            {
                int totalCount = 0;
                int totalPage = 0;
                var list=RoomTypeBLL.GetRoomTypeList(out totalCount, out totalPage,Pageindex,Pagesize,RoomTypName);
                return Ok(new
                {
                    list=list,
                    totalCount=totalCount,
                    totalPage=totalPage
                });
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpGet]
        /// <summary>
        /// 房型Id查询
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IActionResult GetRoomTypeId(int id)
        {
            try
            {
                var list=RoomTypeBLL.GetRoomTypeId(id);
                return Ok(list);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpDelete]
        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IActionResult RoomTypeDel(int id)
        {
            try
            {
                int res= RoomTypeBLL.RoomTypeDel(id);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpPut]
        /// <summary>
        /// 房型修改
        /// </summary>
        /// <param name="roomType"></param>
        /// <returns></returns>
        public IActionResult RoomTypeUpdate(RoomTypeModel info)
        {
            try
            {
               int res= RoomTypeBLL.RoomTypeUpdate(info);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
